<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Searchurl extends MY_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('Search_model');
        $this->load->helper('form');
        $this->load->library('pagination');
    }

    public function index() {

        $config = array();
        $config["base_url"] = base_url() . "searchurl/index";
        $config["total_rows"] = $this->Search_model->record_count();
        $config["per_page"] = 10;
        $config["uri_segment"] = 3;
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->Search_model->fetch_urls($config["per_page"], $page);
        $data["links"] = $this->pagination->create_links();
        //   $data['results'] = $this->Search_model->getUrl();
        $this->data['total_rows'] = $config["total_rows"];
        $this->show_view('searchurl', $data);
    }

    function search_keyword() {
        //Search Engine
        $config = array();
        $config["base_url"] = base_url() . "searchurl/search_keyword";
        $config["total_rows"] = count($this->Search_model->searchUrls1());
        $config["per_page"] = 10;
        $config["uri_segment"] = 3;
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->Search_model->searchUrls($config["per_page"], $page);
        
        $data["links"] = $this->pagination->create_links();
        //   $data['results'] = $this->Search_model->getUrl();
        $this->data['total_rows'] = $config["total_rows"];
       
        $this->show_view('searchurl', $data);
    }

    function DeleteUrl() {
        $this->Search_model->DeleteUrl('$id');
    }

    function editUrl() {
        if (isset($_POST['submit'])) {
            $data = array();
            $data['long_url'] = $this->input->post('long_url');
            $website = $data['long_url'];
            if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $website)) {
                $this->session->set_flashdata('msg', 'Invalid URL, Please enter valid URL');
                redirect(base_url() . 'searchurl/editUrl?id=' . $_GET['id']);
                //echo "Invalid URL";
            } else {
                $data['url'] = $this->Search_model->updateUrl($data);
            }
        } else {

            $data['url'] = $this->Search_model->editUrl();
            $this->show_view('editurl', $data);
        }
    }
    public function pdf() {	
           
		// Load all views as normal
                $data["results"] = $this->Search_model->searchUrls1();
		$this->load->view('searchurlpdf', $data);
		// Get output html
		$html = $this->output->get_output();
		
		// Load library
		$this->load->library('dompdf_gen');
		
		// Convert to PDF
		$this->dompdf->load_html($html);
		$this->dompdf->render();
		$this->dompdf->stream('searchurlpdf');
		
	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
